<template>
  <div>
    <div id="box"></div>
    <vertical-menu></vertical-menu>
    <div class="tabbar">
      <div class="page-header">
        <i class="el-icon-setting iconfont"></i>
        <span>Setting</span>
      </div>
    </div>
    <div id="base">
      <div class="title">
        <i class="el-icon-arrow-left" @click="goBack"></i>
        <span>Public Holiday Setting</span>
        <el-select v-model="year" class="select">
          <el-option
            v-for="item in years"
            :key="item"
            :label="item"
            :value="item"
          ></el-option>
        </el-select>
      </div>
      <div class="table">
        <el-table
          v-loading="loading"
          element-loading-text="Loading"
          element-loading-spinner="el-icon-loading"
          :data="holidayList"
          :cell-style="{textAlign:'center'}"
          :header-cell-style="{background:'rgba(238, 229, 185,0.4)',textAlign:'center',color:'#606266',fontWeight:'600'}"
          border>
          <el-table-column
            prop="startDate"
            label="Strart Date">
          </el-table-column>
          <el-table-column
            prop="endDate"
            label="End Date">
          </el-table-column>
          <el-table-column
            prop="reason"
            label="Reason">
          </el-table-column>
          <el-table-column
            label="Operation">
              <template slot-scope="scope">
                <i class="el-icon-file-editing iconfont" @click="editStaff(scope.row)"></i>
                <i class="el-icon-delete iconfont" @click="deleteStaff(scope.row)"></i>
              </template>
          </el-table-column>
        </el-table>
        <div class="add-wifi" @click="addWifiDialogVisible = true">
          <i class="el-icon-add iconfont"></i>
          <span>Add</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import VerticalMenu from '@/components/VerticalMenu.vue'
export default {
  components: {
    VerticalMenu,
  },
  data(){
    return {
      holidayList: [
        // {
        //   id: 1,
        //   startDate: "2021/7/13",
        //   endDate: '2021/7/15',
        //   reason: 'xxx Festival',
        //   state: true
        // },
        // {
        //   id: 2,
        //   startDate: "2021/6/13",
        //   endDate: '2021/6/15',
        //   reason: 'xxx Festival',
        //   state: true
        // }
      ],
      year: '2021',
      years: ['2019','2020','2021'],
      addWifiDialogVisible: false,
      loading: true,
    }
  },
  created(){

  },
  mounted(){
    this.getPublicHoliday();
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    getDate(date){
      var date = new Date(date);
      var YY = date.getFullYear() + '-';
      var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
      return YY + MM + DD;
    },
    getPublicHoliday(){
      const _this = this;
      _this.$api.setting.getPublicHoliday().then(res => {
        if(res.data.code === 2000){
          _this.holidayList = res.data.data;
          _this.holidayList = _this.holidayList.map((i)=> {
            return {
              id: i.id,
              startDate: _this.getDate(i.startDate),
              endDate: _this.getDate(i.endDate),
              reason: i.reason,
            }
          })
          _this.loading = false;
        }else {
          _this.$message.error(res.data.message)
        }
      }).catch(err => {
        console.log(err);
      })
    }
  }
}
</script>

<style lang="less" scoped>
  #box {
    height: 100%;
    width: 100%;
    position: fixed;
    background-color: #F2F2F2;
    z-index: -1;
  }

  #base {
    padding: 100px 0 0 250px;
  }

  .content {
    padding-bottom: 20px;
    // width: 1260px;
    background-color: #F2F2F2;
    float: left;
  }

  .tabbar {
    margin: 0 0 0 250px;
    padding-top: 10px;
    padding-bottom: 10px;
    background-color: #F2F2F2;
    z-index: 100;
    position: fixed;
  }

  .page-header {
    width: 1234px;
    height: 64px;
    background-color: rgba(242,235,211,0.3);
    border: 2px solid rgba(150, 169, 97,0.5);
    border-radius: 5px;
    margin: 0 20px 0 15px;
    line-height: 64px;
    span {
      color: #473C33;
      margin-left: 10px;
      font-size: 30px;
      // font-weight: 600;
    }
    .el-icon-setting{
      margin-left: 20px;
      font-size: 35px;
      color: #ABC270;
      // vertical-align: middle;
    }
  }

  .title {
    margin-left: 20px;
    padding-right: 30px;
    font-size: 24px;
    font-weight: 600;
    color: #797979;
    .el-icon-arrow-left {
      cursor: pointer;
      font-size: 30px;
      vertical-align: middle;
      margin-right: 10px;
    }
    .select {
      float: right;
    }
  }

  .table {
    margin-top: 20px;
    margin-left: 20px;
    padding-right: 30px;
    .el-icon-delete,.el-icon-file-editing {
      margin-right: 10px;
      font-size: 20px;
      color: rgba(246,119,28,0.9);
      vertical-align: middle;
      cursor: pointer;
    }
  }

  /deep/ .el-table--border{
    border: 2px solid rgba(150, 169, 97,0.5);
  }

  /deep/ .el-table__empty-block {
    background-color: #F2F2F2;
  }

  /deep/ .el-table tr{
    background-color: #F2F2F2;
  }

  /deep/ .el-table--border th{
    border-right: 1px solid rgba(150, 169, 97,0.5);
  }

  /deep/ .el-table td{
    border: 0px;
    border-top: 1px solid rgba(150, 169, 97,0.5);
    border-right: 1px solid rgba(150, 169, 97,0.5);
  }

  .add-wifi {
    cursor: pointer;
    margin-top: 20px;
    width: 100%;
    height: 40px;
    // margin: 10px 10px;
    background-color: rgba(150,169,97,0.2);
    border-radius: 5px;
    line-height: 40px;
    text-align: center;
    color: #96A961;
    font-size: 18px;
    .el-icon-add {
      font-size: 20px;
      color: rgba(246,119,28,0.9);
      margin-right: 10px;
    }
  }
</style>
